<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>IP 属地服务</title>
    <link href="./static/css/css2.css" rel="stylesheet">
    <link href="./static/css/all.min.css" rel="stylesheet">
    <script src="./static/js/tailwindcss.js"></script>
    <script src="./static/js/msgpack/msgpack.min.js"></script>
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#2563EB',
                        secondary: '#4F46E5'
                    },
                    borderRadius: {
                        'none': '0px',
                        'sm': '2px',
                        DEFAULT: '4px',
                        'md': '8px',
                        'lg': '12px',
                        'xl': '16px',
                        '2xl': '20px',
                        '3xl': '24px',
                        'full': '9999px',
                        'button': '4px'
                    }
                }
            }
        }
    </script>
    <style>
        body {
            min-height: 1024px;
        }
        .hero-bg {
            background-image: url('./static/img/4fdec86274c777d2196cd30e958b85e6.jpg');
            background-size: cover;
            background-position: center;
        }
        .copy-btn:hover {
            background-color: rgba(0, 0, 0, 0.05);
        }
        .copy-success {
            opacity: 0;
            transition: opacity 0.3s ease;
        }
        .copy-success.show {
            opacity: 1;
        }
    </style>
</head>
<body class="bg-gray-50">
    <nav class="bg-white shadow-sm fixed w-full z-10">
        <div class="max-w-7xl mx-auto px-4">
            <div class="flex justify-between h-16">
                <div class="flex items-center">
                    <span class="text-2xl font-['Pacifico'] text-primary">logo</span>
                    <span class="ml-4 text-xl font-medium text-gray-900">IP 属地服务</span>
                </div>
                <div class="flex items-center space-x-4">
                    <button class="px-4 py-2 text-sm font-medium text-gray-700 hover:text-primary transition-colors duration-200 !rounded-button whitespace-nowrap">文档</button>
                    <button class="px-4 py-2 text-sm font-medium text-white bg-primary hover:bg-primary/90 transition-colors duration-200 !rounded-button whitespace-nowrap">立即使用</button>
                </div>
            </div>
        </div>
    </nav>

    <div class="hero-bg pt-32 pb-20">
        <div class="max-w-7xl mx-auto px-4">
            <div class="max-w-3xl">
                <h1 class="text-4xl font-bold text-gray-900 mb-6">高性能 IP 属地查询服务</h1>
                <p class="text-lg text-gray-600 mb-8">提供快速、准确的 IP 地理位置查询，支持 IPv4/IPv6 双协议栈，JSON/MessagePack 双数据格式，完美适配您的业务需求。</p>
                <div class="flex space-x-4">
                    <button class="px-6 py-3 bg-primary text-white font-medium hover:bg-primary/90 transition-colors duration-200 !rounded-button whitespace-nowrap">开始使用</button>
                    <button class="px-6 py-3 bg-white text-gray-700 font-medium hover:bg-gray-50 transition-colors duration-200 border border-gray-200 !rounded-button whitespace-nowrap" onclick="document.getElementById('api-doc').scrollIntoView({behavior: 'smooth'})">查看文档</button>
                </div>
            </div>
        </div>
    </div>

    <div class="py-20">
        <div class="max-w-7xl mx-auto px-4">
            <!-- IP 查询模块 -->
            <div class="bg-white rounded-lg shadow-sm p-8 mb-20">
                <h2 class="text-2xl font-semibold text-gray-900 mb-6">IP 归属查询</h2>
                <div class="space-y-6">
                    <!-- 当前IP信息展示 -->
                    <div class="bg-gray-50 p-4 rounded-lg">
                        <div class="mb-2 font-medium text-gray-700">您当前的IP信息：</div>
                        <div class="grid grid-cols-2 gap-4">
                            <div class="flex items-center">
                                <span class="text-gray-500 mr-2">IP地址:</span>
                                <span class="font-medium text-gray-900">{{ .IPInfo.IP }}</span>
                            </div>
                            <div class="flex items-center">
                                <span class="text-gray-500 mr-2">归属国家:</span>
                                <span class="font-medium text-gray-900">{{ .IPInfo.Country }}</span>
                            </div>
                            <div class="flex items-center">
                                <span class="text-gray-500 mr-2">归属省份:</span>
                                <span class="font-medium text-gray-900">{{ .IPInfo.Province }}</span>
                            </div>
                            <div class="flex items-center">
                                <span class="text-gray-500 mr-2">归属城市:</span>
                                <span class="font-medium text-gray-900">{{ .IPInfo.City }}</span>
                            </div>
                            <div class="flex items-center">
                                <span class="text-gray-500 mr-2">运营商:</span>
                                <span class="font-medium text-gray-900">{{ .IPInfo.Isp }}</span>
                            </div>
                            <div class="flex items-center">
                                <span class="text-gray-500 mr-2">查询耗时:</span>
                                <span class="font-medium text-gray-900">{{ .IPInfo.Time }} 微秒</span>
                            </div>
                        </div>
                    </div>
                    
                    <!-- 查询其他IP -->
                    <div>
                        <div class="mb-2 font-medium text-gray-700">查询其他IP地址:</div>
                        <div class="flex items-center">
                            <input id="ipInput" type="text" placeholder="请输入IP地址" class="flex-1 border border-gray-300 rounded-l-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent">
                            <button id="searchIpBtn" class="bg-primary text-white px-4 py-2 rounded-r-lg hover:bg-primary/90 transition-colors duration-200">
                                查询
                            </button>
                        </div>
                        
                        <!-- 查询结果 -->
                        <div id="searchResult" class="mt-4 bg-gray-50 p-4 rounded-lg hidden">
                            <div class="grid grid-cols-2 gap-4">
                                <div class="flex items-center">
                                    <span class="text-gray-500 mr-2">IP地址:</span>
                                    <span id="result-ip" class="font-medium text-gray-900"></span>
                                </div>
                                <div class="flex items-center">
                                    <span class="text-gray-500 mr-2">归属国家:</span>
                                    <span id="result-country" class="font-medium text-gray-900"></span>
                                </div>
                                <div class="flex items-center">
                                    <span class="text-gray-500 mr-2">归属省份:</span>
                                    <span id="result-province" class="font-medium text-gray-900"></span>
                                </div>
                                <div class="flex items-center">
                                    <span class="text-gray-500 mr-2">归属城市:</span>
                                    <span id="result-city" class="font-medium text-gray-900"></span>
                                </div>
                                <div class="flex items-center">
                                    <span class="text-gray-500 mr-2">运营商:</span>
                                    <span id="result-isp" class="font-medium text-gray-900"></span>
                                </div>
                                <div class="flex items-center">
                                    <span class="text-gray-500 mr-2">查询耗时:</span>
                                    <span id="result-time" class="font-medium text-gray-900"></span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="grid grid-cols-3 gap-8 mb-20">
                <div class="bg-white p-8 rounded-lg shadow-sm">
                    <div class="w-12 h-12 bg-primary/10 rounded-lg flex items-center justify-center mb-6">
                        <i class="fas fa-bolt text-primary text-xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold text-gray-900 mb-4">高性能设计</h3>
                    <p class="text-gray-600">采用高效的数据结构和算法，确保微秒级的查询响应速度，轻松应对高并发场景。</p>
                </div>
                <div class="bg-white p-8 rounded-lg shadow-sm">
                    <div class="w-12 h-12 bg-primary/10 rounded-lg flex items-center justify-center mb-6">
                        <i class="fas fa-database text-primary text-xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold text-gray-900 mb-4">双格式支持</h3>
                    <p class="text-gray-600">同时支持 JSON 和 MessagePack 数据格式，满足不同场景下的数据传输需求。</p>
                </div>
                <div class="bg-white p-8 rounded-lg shadow-sm">
                    <div class="w-12 h-12 bg-primary/10 rounded-lg flex items-center justify-center mb-6">
                        <i class="fas fa-network-wired text-primary text-xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold text-gray-900 mb-4">IP 双协议栈</h3>
                    <p class="text-gray-600">完整支持 IPv4 和 IPv6 地址查询，助力您的业务快速适配下一代互联网。</p>
                </div>
            </div>

            <div class="bg-white rounded-lg shadow-sm p-8 mb-20" id="api-doc">
                <h2 class="text-2xl font-semibold text-gray-900 mb-6">Web 服务地址</h2>
                <div class="space-y-6">
                    <div>
                        <div class="flex items-center mb-2">
                            <span class="px-2 py-1 text-xs font-medium bg-blue-100 text-blue-800 rounded">JSON</span>
                        </div>
                        <div class="flex items-center">
                            <div class="flex-1 bg-gray-50 px-4 py-3 rounded-lg font-mono text-sm text-gray-600" id="json-url">
                                https://api.example.com/ip/query/json
                            </div>
                            <button class="copy-btn ml-2 p-2 rounded hover:bg-gray-100 transition-colors duration-200" id="json-copy-btn">
                                <i class="far fa-copy text-gray-400 hover:text-primary"></i>
                            </button>
                        </div>
                    </div>
                    <div>
                        <div class="flex items-center mb-2">
                            <span class="px-2 py-1 text-xs font-medium bg-purple-100 text-purple-800 rounded">MessagePack</span>
                        </div>
                        <div class="flex items-center">
                            <div class="flex-1 bg-gray-50 px-4 py-3 rounded-lg font-mono text-sm text-gray-600" id="msgpack-url">
                                https://api.example.com/ip/query/msgpack
                            </div>
                            <button class="copy-btn ml-2 p-2 rounded hover:bg-gray-100 transition-colors duration-200" id="msgpack-copy-btn">
                                <i class="far fa-copy text-gray-400 hover:text-primary"></i>
                            </button>
                        </div>
                    </div>
                    
                    <!-- API 文档字段说明 -->
                    <div class="mt-8">
                        <h3 class="text-lg font-medium text-gray-900 mb-4">API 文档</h3>
                        
                        <div class="mb-6">
                            <h4 class="text-md font-medium text-gray-800 mb-2">请求参数</h4>
                            <div class="overflow-x-auto">
                                <table class="min-w-full bg-white border border-gray-200 rounded-lg">
                                    <thead>
                                        <tr class="bg-gray-50">
                                            <th class="py-2 px-4 border-b text-left text-sm font-medium text-gray-700">参数名</th>
                                            <th class="py-2 px-4 border-b text-left text-sm font-medium text-gray-700">类型</th>
                                            <th class="py-2 px-4 border-b text-left text-sm font-medium text-gray-700">必填</th>
                                            <th class="py-2 px-4 border-b text-left text-sm font-medium text-gray-700">描述</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td class="py-2 px-4 border-b text-sm text-gray-800">ip</td>
                                            <td class="py-2 px-4 border-b text-sm text-gray-600">string</td>
                                            <td class="py-2 px-4 border-b text-sm text-gray-600">否</td>
                                            <td class="py-2 px-4 border-b text-sm text-gray-600">要查询的IP地址，IPv4或IPv6格式。若不提供则使用请求者IP</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        
                        <div class="mb-6">
                            <h4 class="text-md font-medium text-gray-800 mb-2">响应字段</h4>
                            <div class="overflow-x-auto">
                                <table class="min-w-full bg-white border border-gray-200 rounded-lg">
                                    <thead>
                                        <tr class="bg-gray-50">
                                            <th class="py-2 px-4 border-b text-left text-sm font-medium text-gray-700">字段名</th>
                                            <th class="py-2 px-4 border-b text-left text-sm font-medium text-gray-700">类型</th>
                                            <th class="py-2 px-4 border-b text-left text-sm font-medium text-gray-700">描述</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td class="py-2 px-4 border-b text-sm text-gray-800">code</td>
                                            <td class="py-2 px-4 border-b text-sm text-gray-600">int</td>
                                            <td class="py-2 px-4 border-b text-sm text-gray-600">状态码，200表示成功</td>
                                        </tr>
                                        <tr class="bg-blue-50">
                                            <td class="py-2 px-4 border-b text-sm font-medium text-blue-800">data</td>
                                            <td class="py-2 px-4 border-b text-sm text-blue-600">object</td>
                                            <td class="py-2 px-4 border-b text-sm text-blue-600">IP信息数据对象</td>
                                        </tr>
                                        <tr>
                                            <td class="py-2 px-4 border-b text-sm text-gray-800">
                                                <div class="flex items-center">
                                                    <span class="inline-block w-4 h-[1px] bg-gray-300 mr-2"></span>
                                                    <span class="inline-block border-l border-gray-300 h-4 mr-2"></span>
                                                    <span>data.ip</span>
                                                </div>
                                            </td>
                                            <td class="py-2 px-4 border-b text-sm text-gray-600">string</td>
                                            <td class="py-2 px-4 border-b text-sm text-gray-600">查询的IP地址</td>
                                        </tr>
                                        <tr>
                                            <td class="py-2 px-4 border-b text-sm text-gray-800">
                                                <div class="flex items-center">
                                                    <span class="inline-block w-4 h-[1px] bg-gray-300 mr-2"></span>
                                                    <span class="inline-block border-l border-gray-300 h-4 mr-2"></span>
                                                    <span>data.country</span>
                                                </div>
                                            </td>
                                            <td class="py-2 px-4 border-b text-sm text-gray-600">string</td>
                                            <td class="py-2 px-4 border-b text-sm text-gray-600">IP归属国家</td>
                                        </tr>
                                        <tr>
                                            <td class="py-2 px-4 border-b text-sm text-gray-800">
                                                <div class="flex items-center">
                                                    <span class="inline-block w-4 h-[1px] bg-gray-300 mr-2"></span>
                                                    <span class="inline-block border-l border-gray-300 h-4 mr-2"></span>
                                                    <span>data.province</span>
                                                </div>
                                            </td>
                                            <td class="py-2 px-4 border-b text-sm text-gray-600">string</td>
                                            <td class="py-2 px-4 border-b text-sm text-gray-600">IP归属省份</td>
                                        </tr>
                                        <tr>
                                            <td class="py-2 px-4 border-b text-sm text-gray-800">
                                                <div class="flex items-center">
                                                    <span class="inline-block w-4 h-[1px] bg-gray-300 mr-2"></span>
                                                    <span class="inline-block border-l border-gray-300 h-4 mr-2"></span>
                                                    <span>data.city</span>
                                                </div>
                                            </td>
                                            <td class="py-2 px-4 border-b text-sm text-gray-600">string</td>
                                            <td class="py-2 px-4 border-b text-sm text-gray-600">IP归属城市</td>
                                        </tr>
                                        <tr>
                                            <td class="py-2 px-4 border-b text-sm text-gray-800">
                                                <div class="flex items-center">
                                                    <span class="inline-block w-4 h-[1px] bg-gray-300 mr-2"></span>
                                                    <span class="inline-block border-l border-gray-300 h-4 mr-2"></span>
                                                    <span>data.isp</span>
                                                </div>
                                            </td>
                                            <td class="py-2 px-4 border-b text-sm text-gray-600">string</td>
                                            <td class="py-2 px-4 border-b text-sm text-gray-600">IP归属运营商</td>
                                        </tr>
                                        <tr>
                                            <td class="py-2 px-4 border-b text-sm text-gray-800">
                                                <div class="flex items-center">
                                                    <span class="inline-block w-4 h-[1px] bg-gray-300 mr-2"></span>
                                                    <span class="inline-block border-l border-gray-300 h-4 mr-2"></span>
                                                    <span>data.time</span>
                                                </div>
                                            </td>
                                            <td class="py-2 px-4 border-b text-sm text-gray-600">int64</td>
                                            <td class="py-2 px-4 border-b text-sm text-gray-600">查询耗时(微秒)</td>
                                        </tr>
                                        <tr>
                                            <td class="py-2 px-4 border-b text-sm text-gray-800">message</td>
                                            <td class="py-2 px-4 border-b text-sm text-gray-600">string</td>
                                            <td class="py-2 px-4 border-b text-sm text-gray-600">错误信息，仅在code不为200时出现</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        
                        <div>
                            <h4 class="text-md font-medium text-gray-800 mb-2">示例响应</h4>
                            <div class="bg-gray-50 p-4 rounded-lg">
                                <pre class="text-sm whitespace-pre overflow-x-auto"><span class="text-gray-600">{</span>
    <span class="text-purple-700">"code"</span><span class="text-gray-600">:</span> <span class="text-blue-600">200</span>,
    <span class="text-purple-700">"data"</span><span class="text-gray-600">:</span> <span class="text-gray-600">{</span>
        <span class="text-purple-700">"ip"</span><span class="text-gray-600">:</span> <span class="text-green-600">"8.8.8.8"</span>,
        <span class="text-purple-700">"country"</span><span class="text-gray-600">:</span> <span class="text-green-600">"美国"</span>,
        <span class="text-purple-700">"province"</span><span class="text-gray-600">:</span> <span class="text-green-600">""</span>,
        <span class="text-purple-700">"city"</span><span class="text-gray-600">:</span> <span class="text-green-600">""</span>,
        <span class="text-purple-700">"isp"</span><span class="text-gray-600">:</span> <span class="text-green-600">"Google公司"</span>,
        <span class="text-purple-700">"time"</span><span class="text-gray-600">:</span> <span class="text-blue-600">156</span>
    <span class="text-gray-600">}</span>
<span class="text-gray-600">}</span></pre>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="bg-white rounded-lg shadow-sm p-8">
                <h2 class="text-2xl font-semibold text-gray-900 mb-6">技术规格</h2>
                <div class="grid grid-cols-2 gap-8">
                    <div>
                        <h3 class="text-lg font-medium text-gray-900 mb-4">数据格式</h3>
                        <ul class="space-y-3 text-gray-600">
                            <li class="flex items-center">
                                <i class="fas fa-check text-green-500 mr-2"></i>
                                JSON 格式支持
                            </li>
                            <li class="flex items-center">
                                <i class="fas fa-check text-green-500 mr-2"></i>
                                MessagePack 格式支持
                            </li>
                            <li class="flex items-center">
                                <i class="fas fa-check text-green-500 mr-2"></i>
                                UTF-8 编码
                            </li>
                        </ul>
                    </div>
                    <div>
                        <h3 class="text-lg font-medium text-gray-900 mb-4">性能指标</h3>
                        <ul class="space-y-3 text-gray-600">
                            <li class="flex items-center">
                                <i class="fas fa-check text-green-500 mr-2"></i>
                                平均响应时间 < 5ms
                            </li>
                            <li class="flex items-center">
                                <i class="fas fa-check text-green-500 mr-2"></i>
                                99.9% 可用性保证
                            </li>
                            <li class="flex items-center">
                                <i class="fas fa-check text-green-500 mr-2"></i>
                                支持每秒千级查询
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
            
            <!-- 源码地址 -->
            <div class="bg-white rounded-lg shadow-sm p-8 mt-20">
                <h2 class="text-2xl font-semibold text-gray-900 mb-6">开源代码</h2>
                <p class="text-gray-600 mb-6">本项目完全开源，欢迎查看源码、提交问题或贡献代码。您可以通过以下平台访问我们的代码库：</p>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                    <div class="border border-gray-200 rounded-lg p-6 transition-all duration-300 hover:shadow-md">
                        <div class="flex items-center mb-4">
                            <i class="fab fa-github text-2xl text-gray-800 mr-3"></i>
                            <h3 class="text-lg font-medium text-gray-900">GitHub</h3>
                        </div>
                        <p class="text-gray-600 mb-4">GitHub 是全球最大的代码托管平台，提供完整的 Git 工作流程</p>
                        <div class="flex items-center">
                            <a href="#" id="github-link" class="flex-1 bg-gray-50 px-4 py-3 rounded-lg font-mono text-sm text-gray-600 truncate">
                                <!-- 地址将手动填写 -->
                            </a>
                            <button class="copy-btn ml-2 p-2 rounded hover:bg-gray-100 transition-colors duration-200" id="github-copy-btn">
                                <i class="far fa-copy text-gray-400 hover:text-primary"></i>
                            </button>
                        </div>
                        <div class="mt-4">
                            <a href="#" id="github-visit-btn" class="inline-flex items-center justify-center px-4 py-2 bg-gray-900 hover:bg-gray-800 text-white rounded-lg transition-colors duration-200 w-full">
                                <i class="fas fa-external-link-alt mr-2"></i> 前往 GitHub
                            </a>
                        </div>
                    </div>
                    
                    <div class="border border-gray-200 rounded-lg p-6 transition-all duration-300 hover:shadow-md">
                        <div class="flex items-center mb-4">
                            <i class="fab fa-git-alt text-2xl text-red-600 mr-3"></i>
                            <h3 class="text-lg font-medium text-gray-900">Gitee</h3>
                        </div>
                        <p class="text-gray-600 mb-4">Gitee 是中国领先的代码托管平台，访问速度更快</p>
                        <div class="flex items-center">
                            <a href="#" id="gitee-link" class="flex-1 bg-gray-50 px-4 py-3 rounded-lg font-mono text-sm text-gray-600 truncate">
                                <!-- 地址将手动填写 -->
                            </a>
                            <button class="copy-btn ml-2 p-2 rounded hover:bg-gray-100 transition-colors duration-200" id="gitee-copy-btn">
                                <i class="far fa-copy text-gray-400 hover:text-primary"></i>
                            </button>
                        </div>
                        <div class="mt-4">
                            <a href="#" id="gitee-visit-btn" class="inline-flex items-center justify-center px-4 py-2 bg-red-600 hover:bg-red-700 text-white rounded-lg transition-colors duration-200 w-full">
                                <i class="fas fa-external-link-alt mr-2"></i> 前往 Gitee
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <footer class="bg-gray-900 py-12">
        <div class="max-w-7xl mx-auto px-4">
            <div class="grid grid-cols-4 gap-8">
                <div>
                    <span class="text-2xl font-['Pacifico'] text-white mb-4 block">logo</span>
                    <p class="text-gray-400">提供专业的 IP 属地查询服务，为您的业务保驾护航。</p>
                </div>
                <div>
                    <h4 class="text-white font-medium mb-4">产品</h4>
                    <ul class="space-y-2">
                        <li><a href="#" class="text-gray-400 hover:text-white transition-colors duration-200">功能特性</a></li>
                        <li><a href="#" class="text-gray-400 hover:text-white transition-colors duration-200">技术文档</a></li>
                        <li><a href="#" class="text-gray-400 hover:text-white transition-colors duration-200">更新日志</a></li>
                    </ul>
                </div>
                <div>
                    <h4 class="text-white font-medium mb-4">支持</h4>
                    <ul class="space-y-2">
                        <li><a href="#" class="text-gray-400 hover:text-white transition-colors duration-200">帮助中心</a></li>
                        <li><a href="#" class="text-gray-400 hover:text-white transition-colors duration-200">API 文档</a></li>
                        <li><a href="#" class="text-gray-400 hover:text-white transition-colors duration-200">联系我们</a></li>
                    </ul>
                </div>
                <div>
                    <h4 class="text-white font-medium mb-4">关注我们</h4>
                    <div class="flex space-x-4">
                        <a href="#" class="text-gray-400 hover:text-white transition-colors duration-200">
                            <i class="fab fa-github text-xl"></i>
                        </a>
                        <a href="#" class="text-gray-400 hover:text-white transition-colors duration-200">
                            <i class="fab fa-twitter text-xl"></i>
                        </a>
                    </div>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-12 pt-8">
                <p class="text-gray-400 text-center">© 2024 IP 属地服务. 保留所有权利。</p>
            </div>
        </div>
    </footer>

    <script>
        function copyToClipboard(button, text) {
            navigator.clipboard.writeText(text).then(() => {
                const icon = button.querySelector('i');
                icon.classList.remove('far', 'fa-copy');
                icon.classList.add('fas', 'fa-check');
                icon.style.color = '#22c55e';

                setTimeout(() => {
                    icon.classList.remove('fas', 'fa-check');
                    icon.classList.add('far', 'fa-copy');
                    icon.style.color = '';
                }, 2000);
            });
        }

        // IP查询功能
        document.addEventListener('DOMContentLoaded', function() {
            const searchIpBtn = document.getElementById('searchIpBtn');
            const ipInput = document.getElementById('ipInput');
            const searchResult = document.getElementById('searchResult');
            
            // 设置动态API URL
            const baseUrl = window.location.origin; // 获取当前域名和端口
            const jsonUrl = `${baseUrl}/json`;
            const msgpackUrl = `${baseUrl}/msgpack`;
            
            // 更新显示的URL
            const jsonUrlElement = document.getElementById('json-url');
            const msgpackUrlElement = document.getElementById('msgpack-url');
            if (jsonUrlElement) jsonUrlElement.textContent = jsonUrl;
            if (msgpackUrlElement) msgpackUrlElement.textContent = msgpackUrl;
            
            // 更新复制按钮
            const jsonCopyBtn = document.getElementById('json-copy-btn');
            const msgpackCopyBtn = document.getElementById('msgpack-copy-btn');
            if (jsonCopyBtn) {
                jsonCopyBtn.addEventListener('click', function() {
                    copyToClipboard(this, jsonUrl);
                });
            }
            if (msgpackCopyBtn) {
                msgpackCopyBtn.addEventListener('click', function() {
                    copyToClipboard(this, msgpackUrl);
                });
            }
            
            // 源码地址链接和复制功能
            const githubLink = document.getElementById('github-link');
            const giteeLink = document.getElementById('gitee-link');
            const githubVisitBtn = document.getElementById('github-visit-btn');
            const giteeVisitBtn = document.getElementById('gitee-visit-btn');
            const githubCopyBtn = document.getElementById('github-copy-btn');
            const giteeCopyBtn = document.getElementById('gitee-copy-btn');
            
            // 稍后手动填写的地址
            const githubRepoUrl = "https://github.com/OlnyBigRoc/cz-ip-service"; 
            const giteeRepoUrl = "https://gitee.com/big_roc_admin/cz-ip-service";  
            
            // 设置源码链接显示和访问
            if (githubLink && githubVisitBtn) {
                if (githubRepoUrl) {
                    githubLink.textContent = githubRepoUrl;
                    githubLink.href = githubRepoUrl;
                    githubLink.target = "_blank"; // 在新标签页打开
                    githubLink.rel = "noopener noreferrer"; // 安全措施
                    githubVisitBtn.href = githubRepoUrl;
                    githubVisitBtn.target = "_blank"; // 在新标签页打开
                    githubVisitBtn.rel = "noopener noreferrer"; // 安全措施
                } else {
                    githubLink.textContent = "即将上线...";
                    githubVisitBtn.classList.add('opacity-50', 'cursor-not-allowed');
                    githubVisitBtn.removeAttribute('href');
                }
            }
            
            if (giteeLink && giteeVisitBtn) {
                if (giteeRepoUrl) {
                    giteeLink.textContent = giteeRepoUrl;
                    giteeLink.href = giteeRepoUrl;
                    giteeLink.target = "_blank"; // 在新标签页打开
                    giteeLink.rel = "noopener noreferrer"; // 安全措施
                    giteeVisitBtn.href = giteeRepoUrl;
                    giteeVisitBtn.target = "_blank"; // 在新标签页打开
                    giteeVisitBtn.rel = "noopener noreferrer"; // 安全措施
                } else {
                    giteeLink.textContent = "即将上线...";
                    giteeVisitBtn.classList.add('opacity-50', 'cursor-not-allowed');
                    giteeVisitBtn.removeAttribute('href');
                }
            }
            
            // 复制按钮功能
            if (githubCopyBtn && githubRepoUrl) {
                githubCopyBtn.addEventListener('click', function() {
                    copyToClipboard(this, githubRepoUrl);
                });
            }
            
            if (giteeCopyBtn && giteeRepoUrl) {
                giteeCopyBtn.addEventListener('click', function() {
                    copyToClipboard(this, giteeRepoUrl);
                });
            }

            if (searchIpBtn && ipInput) {
                searchIpBtn.addEventListener('click', function() {
                    const ip = ipInput.value.trim();
                    if (!ip) {
                        alert('请输入IP地址');
                        return;
                    }
                    
                    // 显示加载状态
                    searchIpBtn.disabled = true;
                    searchIpBtn.innerHTML = '查询中...';
                    
                    // 发送请求到msgpack接口，使用动态URL
                    fetch(`${msgpackUrl}?ip=${encodeURIComponent(ip)}`, {
                        headers: {
                            'Accept': 'application/x-msgpack'
                        }
                    })
                    .then(response => {
                        if (!response.ok) {
                            throw new Error('响应不成功: ' + response.status);
                        }
                        // 获取MessagePack数据
                        return response.arrayBuffer();
                    })
                    .then(buffer => {
                        // 使用msgpack-lite库解析MessagePack数据
                        const data = msgpack.decode(new Uint8Array(buffer));
                        
                        searchIpBtn.disabled = false;
                        searchIpBtn.innerHTML = '查询';
                        
                        if (data.code === 200) {
                            // 显示结果
                            document.getElementById('result-ip').textContent = data.data.ip || '';
                            document.getElementById('result-country').textContent = data.data.country || '';
                            document.getElementById('result-province').textContent = data.data.province || '';
                            document.getElementById('result-city').textContent = data.data.city || '';
                            document.getElementById('result-isp').textContent = data.data.isp || '';
                            document.getElementById('result-time').textContent = (data.data.time || '0') + ' 微秒';
                            
                            // 显示结果区域
                            searchResult.classList.remove('hidden');
                        } else {
                            alert('查询失败: ' + (data.message || '未知错误'));
                        }
                    })
                    .catch(error => {
                        console.error('使用msgpack接口出错:', error);
                        // 如果msgpack失败，回退到json接口，使用动态URL
                        fetch(`${jsonUrl}?ip=${encodeURIComponent(ip)}`)
                            .then(response => response.json())
                            .then(data => {
                                searchIpBtn.disabled = false;
                                searchIpBtn.innerHTML = '查询';
                                
                                if (data.code === 200) {
                                    // 显示结果
                                    document.getElementById('result-ip').textContent = data.data.ip || '';
                                    document.getElementById('result-country').textContent = data.data.country || '';
                                    document.getElementById('result-province').textContent = data.data.province || '';
                                    document.getElementById('result-city').textContent = data.data.city || '';
                                    document.getElementById('result-isp').textContent = data.data.isp || '';
                                    document.getElementById('result-time').textContent = (data.data.time || '0') + ' 微秒';
                                    
                                    // 显示结果区域
                                    searchResult.classList.remove('hidden');
                                } else {
                                    alert('查询失败: ' + (data.message || '未知错误'));
                                }
                            })
                            .catch(err => {
                                searchIpBtn.disabled = false;
                                searchIpBtn.innerHTML = '查询';
                                alert('查询出错: ' + err.message);
                            });
                    });
                });
                
                // 支持回车键查询
                ipInput.addEventListener('keypress', function(e) {
                    if (e.key === 'Enter') {
                        searchIpBtn.click();
                    }
                });
            }
        });
    </script>
</body>
</html>